package com.sinux.sshUser.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinux.sshUser.entity.User;
import com.sinux.sshUser.service.UserServiceI;


@Controller
public class SeachController {

	@Autowired
	private UserServiceI userService;

	@RequestMapping("/showss")
	public String index(HttpServletRequest request, HttpServletResponse response, Model model) {

		List<User> list = new ArrayList<User>();
		list = (List<User>) request.getSession().getAttribute("userList");// user为空
		// 判断是否为空
		if (list.size() == 0) {
			return "index2";
		} else {
			System.out.println("index:"+list);
			model.addAttribute("userList", list);
			return "index1";
		}
	}
	
	@RequestMapping("/seach")
	public String searchID(HttpServletRequest request, HttpServletResponse response, Model model) {
		return "index1";
	}
	// 数据提交到这里
	@ResponseBody
	@RequestMapping("/ifseach")
	public Object ifSearch(HttpServletRequest request, HttpServletResponse response, User user) {
		Map<String, Object> map = new HashMap<String, Object>();
		user.setUid(user.getUid());
		System.out.println("*************\nSearch ID:" + user.getUid());
		User user1=new User();//测试
		user1.setUid("170502");//测试
		//List<User> list = userService.selectInfo(user1);
		List<User> list=null;
		if (list.size() == 0) {
			System.out.println("msg.失败！");
			map.put("success", false);
			map.put("msg", "失败！");
		} else {
			System.out.println("ifSearch:"+list.get(0).getUname());
			request.getSession().setAttribute("userList", list);
			map.put("success", true);
			map.put("msg", "成功！");
		}
		return map;
		

	}

}
